<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-touch-fullscreen" content="yes">
  <meta name="msapplication-tap-highlight" content="no">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <title>个人信息</title>
  <link rel="shortcut icon" href="/favicon.ico">
  <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/bootstrap-4.2.1/css/bootstrap.min.css">
  <link rel="stylesheet" href="${pageContext.request.contextPath }/user/SUI_Mobile/sm.min.css">
  <link rel="stylesheet" href="${pageContext.request.contextPath }/user/SUI_Mobile/sm-extend.min.css">
  <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/user/css/common.css">
</head>
<body>
  <div class="container">
    <header class="bar bar-nav header sticky-top">
      <a class="button button-link button-nav pull-left back" href="#" onclick="history.go(-1)">
        <span class="icon icon-left"></span>返回
      </a>
      <h1 class='title'>我的信息</h1>
    </header>
    <!-- 中间，记录显示 -->
    <div class="mainContent">
      <form class="list-block">
        <input type="text" class="uid" value="${user.uid }" style="display:none;">
        <ul>
          <li>
            <div class="item-content">
              <div class="item-inner">
                <div class="label">用户名</div>
                <div class="item-input">
                  <input type="text" class="username" value="${user.username }" readonly>
                </div>
              </div>
            </div>
          </li>
          <li>
            <div class="item-content">
              <div class="item-inner">
                <div class="label">真实姓名</div>
                <div class="item-input">
                  <input type="text" class="realname" value="${user.realname }">
                </div>
              </div>
            </div>
          </li>
          <li>
            <div class="item-content">
              <div class="item-inner">
                <div class="label">联系方式</div>
                <div class="item-input">
                  <input type="text" class="cellphone" value="${user.cellphone }">
                </div>
              </div>
            </div>
          </li>
          <li>
            <div class="item-content">
              <div class="item-inner">
                <div class="label">邮箱</div>
                <div class="item-input">
                  <input type="email" class="email" value="${user.email }">
                </div>
              </div>
            </div>
          </li>
          <li>
            <div class="item-content">
              <div class="item-inner">
                <div class="label">性别</div>
                <div class="item-input">
                  <div class="custom-control custom-radio custom-control-inline">
                    <input type="radio" id="man" name="gender" class="custom-control-input" value="1" 
                      <c:if test="${user.gender=='1'}">checked="checked"</c:if>>
                    <label class="custom-control-label" for="man" style="padding-top:4px;">男</label>
                  </div>
                  <div class="custom-control custom-radio custom-control-inline">
                    <input type="radio" id="woman" name="gender" class="custom-control-input" value="0" 
                      <c:if test="${user.gender=='0'}">checked="checked"</c:if>>
                    <label class="custom-control-label" for="woman" style="padding-top:4px;">女</label>
                  </div>
                </div>
              </div>
            </div>
          </li>
          <li class="align-top">
            <div class="item-content">
              <div class="item-inner" style="border-bottom: 0.5px solid #E7E7E7;margin-bottom: 5px;">
                <div class="label">个人简介</div>
                <div class="item-input">
                  <textarea class="resume">${user.resume }</textarea>
                </div>
              </div>
            </div>
          </li>
        </ul>
      </form>
      <div class="content-block">
        <div class="row">
          <div class="col"><a href="javascript:;" class="button button-big button-fill button-success confirmEditBtn">确定</a></div>
        </div>
      </div><!-- end of .content-block -->
      <div class="modal toast modal-out" style="display:block;margin-top:-24px;margin-left:-48px;"></div>
    </div><!-- end of .mainContent -->
  </div> <!-- end of .container -->

  <script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery-3.3.1.min.js" charset="utf-8"></script>
  <script type='text/javascript' src='${pageContext.request.contextPath }/user/SUI_Mobile/zepto.min.js' charset='utf-8'></script>
  <script type='text/javascript' src='${pageContext.request.contextPath }/user/SUI_Mobile/sm-extend.min.js' charset='utf-8'></script>
  <script type="text/javascript" src="${pageContext.request.contextPath }/bootstrap-4.2.1/js/bootstrap.min.js" charset="utf-8"></script>
  <script>
    $(function () {
      $('.confirmEditBtn').on('click', function(){
    	  if($('.cellphone').val()==''||$('.cellphone').val()==null){
    		  $('.cellphone').focus()
    	  } else {
    		  var uid = $('.uid').val()
    		  var realname = $('.realname').val()
    		  var cellphone = $('.cellphone').val()
    		  var email = $('.email').val()
    		  var gender = $("input:radio[name='gender']:checked").val()
    		  var resume = $('.resume').val()
    		  $.post(
    				"/LostAndFound/me?method=editMyInfo",
    				{
    					"uid":uid,
    					"realname":realname,
    					"cellphone":cellphone,
    					"email":email,
    					"gender":gender,
    					"resume":resume
    				},
    				function(data){
    					showToastByTime(data.success)
    				},
    				"json"
    		  );
    	  }
      });
    })
    // 显示提示，然后跳转页面
    function showToastByTime ( successFlag ) {
      var info = null;
      if( successFlag ){
        info = '修改成功'
      }else {
        info = '修改失败'
      }
      clearTimeout(timer)
      $('.toast').text(info)    
      $('.toast').addClass('modal-in')
      $('.toast').removeClass('modal-out')
      var timer = window.setTimeout(function () {
        $('.toast').addClass('modal-out')
        $('.toast').removeClass('modal-int')
      }, 2000)
    }
  </script>

</body>
</html>